"""
URL configuration for djangodemo project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.http import HttpResponse
from django.urls import path
from django.urls import include
from user import views as user_views
from path_demo import views as path_demo_views
from django.shortcuts import render
from django.conf.urls.static import static
from django.conf import settings
from mysqldemo import views as mysql_demo_views


# 视图函数（一般是放到其他模块里的，此处引入进来）
def hello_world(request):
    return HttpResponse("你好世界，Hello, world!")

def test_static_file(request):
    return render(request,'test_static_file.html')

# 路由配置
urlpatterns = [
    path('admin/', admin.site.urls), # Django自带的admin后台
    path('hello', hello_world),
    path('user/search', user_views.query_user_by_name,name='user_search'), # 用户模块的视图函数
    path('user/<int:user_id>', user_views.user_detail), # 用户模块的视图函数
    path('user/login', user_views.login, name='login'), # 用户模块的视图函数
    path('user/register', user_views.register, name='register'), # 用户模块的视图函数
    path('user/home', user_views.home, name='home'), # 用户模块的视图函数
    path('test/getJsonRequestBody', user_views.test_get_request_body, name='test_json_request_body'), # 用户模块的视图函数

    path('pathDemo/testIntConvert/<int:id>', path_demo_views.test_int_convert,None,'path_demo1'),
    path('pathDemo/testSlugConvert/<slug:slug_text>', path_demo_views.test_slug_convert,None,'path_demo2'),
    path('pathDemo/testUUIDConvert/<uuid:uuid_text>', path_demo_views.test_uuid_convert,None,'path_demo3'),
    path('pathDemo/testKwards', path_demo_views.test_kwards, {'key_1':'abc','key_2':123},'path_demo3'),

    path('course/', include('course.urls')), # 引入课程模块的路由配置


    path('testReverseWithNamespace', path_demo_views.test_reverse_with_namespace, name='test_reverse_with_namespace'),
    path('testReverseWithPathVariable', path_demo_views.test_reverse_with_path_variable, name='test_reverse_with_path_variable'),
    path('testReverseWithQueryParameter', path_demo_views.test_reverse_with_query_parameter, name='test_reverse_with_query_parameter'),



    path('testStaticFile/', test_static_file), # 引入课程模块的路由配置

    path('querySql', mysql_demo_views.test_query_sql, name='query_sql'), # 引入课程模块的路由配置


    path('addUser', user_views.add_user, name='add_user'), # 引入课程模块的路由配置
    path('deleteUser/<int:id>', user_views.delete_user, name='delete_user'), # 引入课程模块的路由配置
    path('updateUser', user_views.update_user, name='update_user'), # 引入课程模块的路由配置
    path('queryUserAll', user_views.query_all, name='query_user_all'), # 引入课程模块的路由配置
    path('queryUserByName', user_views.query_by_name, name='query_user_by_name'), # 引入课程模块的路由配置
    path('queryUserById/<int:id>', user_views.query_by_id, name='query_user_by_id'), # 引入课程模块的路由配置
] + static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
